package cn.itcast.bos.service.standard.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.StandardDao;
import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.standard.StandardService;
@Service
@Transactional
public class StandardServiceImp implements StandardService {
	@Autowired
	private StandardDao standardDao;
	
	public void save(Standard standard) {
		standardDao.save(standard);
		
	}

	
	public Page<Standard> findAll(Pageable pageable) {
		
		return standardDao.findAll(pageable);
	}


	@Override
	public List <Standard> findAll() {
		
		return standardDao.findAll();
	}


	public Page<Standard> findPageData(Specification<Standard> specification,
			Pageable pageable) {
		
		return standardDao.findAll(specification, pageable);
	}


	public void delete(String ids) {
		String [] arr = ids.split("-");
		for(int i = 0;i<arr.length;i++){
			int  id = Integer.parseInt(arr[i]);
			Standard standard=standardDao.findOne(id);
			standard.setState("0");
			
		}
		
	}


	@Override
	public void restore(String ids) {
		String [] arr = ids.split("-");
		for(int i = 0;i<arr.length;i++){
			int  id = Integer.parseInt(arr[i]);
			Standard standard=standardDao.findOne(id);
			standard.setState("1");
			
		}
		
	}

}
